function setInnerWithUrlData(url,nodeId){
	dojo.xhrGet({
				url: url,
				handleAs: "text",
				handle: function(data,args){
				if(typeof data == "error"){
					alert("error!");
				}else{
					setInner(nodeId,data,200);
				}
			}
	});
}

function setInner(nodeId,data,time){
	if (time=="undefined"){
		time=0;
	}
	setTimeout(function(){
					var node = dojo.byId(nodeId);
					if(!node){
						alert("setInnerError:"+nodeId);
					}else{
						//alert("handleWidgetDestroy");
						handleWidgetDestroy(node);
						node.innerHTML = data;				
						dojo.parser.parse(node);
					}
				},
				time);
}

function handleWidgetDestroy(root){
	if(root && root.hasChildNodes()){
			//alert("handle "+root+","+root.childNodes.length+" children");
			var child = root.firstChild;
			while(child){
				if(child.nodeType=="1"){							
					handleWidgetDestroy(child);

					if(dijit.byNode(child)){
						dijit.byNode(child).destroy();
						//alert(child.id+" has been destroied!");	
					}			
				}
				child = child.nextSibling;
			}
	}
}

function clearDiv(id){
	handleWidgetDestroy(dojo.byId(id));
	var _root = dojo.byId(id);
	if(_root && _root.hasChildNodes()){
			//alert("handle "+_root+","+_root.childNodes.length+" children");
			var _child = _root.firstChild;
			while(_child){
				_root.removeChild(_child);
				//Can't insure that domObj has been cleared when removed from parent DomObj
				_oldChild = _child;
				_child = _child.nextSibling;
				_oldChild = null;
			}
	}
}

var EventManager = {
	_registry: null,
	initialis: function(){
		if(this._registry == null){
			this._registry = [];
			this.add(window,"unload",this.clear);
		}
	},
   //attach event and add this record into registry
	add: function(obj, evt, evtHandler, useCapture){
		this.initialis();
		if(typeof obj == "string"){
			obj = dojo.byId(obj);
		}
		if(obj == null || evtHandler == null){
			return false;
		}		
		//On Firefox
		if(obj.addEventListener){
			obj.addEventListener(evt, evtHandler, useCapture);
			this._registry.push({
				"obj":obj, "evt":evt, "evtHandler":evtHandler, "useCapture":useCapture 
			});
			return true;
		}
		//On Ie
		else if(obj.attachEvent && obj.attachEvent("on"+evt, evtHandler)){
			this._registry.push({
				"obj":obj, "evt":evt, "evtHandler":evtHandler, "useCapture":false 
			});
			return true;
		}
		return false;		
	},
	//clear up registry
	clear: function(){
		for(var i=0; i<EventManager._rgistry.length; i++){
			var em = EventManager._rigstry[i];
			if(em["obj"].removeEventListener){
				em["obj"].removeEventListener(em["evt"], em["evtHandler"], em["useCapture"]);
			}else if(em["obj"].detachEvent){
				em["obj"].detachEvent("on"+em["evt"], em["evtHandler"]);
			}			
		}
		EventManager._regsitry = null;
	}
}

function registerWidgetCheck(id){
	if(dijit.byId(id)){
		dijit.byId(id).destroy();
	}
}
function createDomInput(attr){
	var input = document.createElement("input");
	if(attr["type"] && attr["type"]!=""){
	   input.type=attr["type"];
	}
	if(attr["id"] && attr["id"]!=""){
	   input.id=attr["id"];
	}
	if(attr["name"] && attr["name"]!=""){
	   input.name=attr["name"];
	}
	return input;
}
function creatDomLabel(innerHTML){
	var label = document.createElement("label");
	if(innerHTML){
	   label.innerHTML= innerHTML;
	}
	return label
}
function createDomTabel(attr){
	if(!attr["row"] || attr["row"]<0){
		attr["row"] = 0;
	}
	if(!attr["col"] || attr["col"]<0){
		attr["col"] = 0;
	}
	var table = document.createElement("table");
	
	for(var r=0; r<attr["row"]; r++){
		var _row = table.insertRow(r);
		for(var c=0; c<attr["col"]; c++){
			_row.insertCell(c);
		}
	}
	return table;	
}
function creatShortValiInput(attr){
	var input = new dijit.form.ValidationTextBox(attr);
	if(attr["regExpId"]){
		input.attr("regExpGen",function(constraints){
			return regExpIndex(attr["regExpId"],constraints.locale);
		});
	}
	input.attr("style","width :250px");
//	alert(input.attr("regExpGen"));
	return  input;
}
function creatLongValiInput(attr){
	var input = new dijit.form.ValidationTextBox(attr);
	input.attr("style","width :400px");
	return  input;
}
function creatLongTextarea(attr){
	var textarea = document.createElement("textarea");
	textarea.id= attr["id"];
	textarea.name= attr["name"];
	textarea.className = "des";
	return  textarea;
}